//  this library.
import 'package:hktk_app/ienum/question/first_type_enum.dart';

/// 试题相关模型
class PracticeQuestionModel {
  String? id;
  FirstTypeEnum? firstType;
  String? type;
  String? difficulty;
  List<Stem>? stem;
  List<dynamic>? quOption;
  List<Stem>? answerDesc;
  String? children;
  RecordModel? record;
  dynamic rightAnswer;
  String? answerBase64;
  String? sign;
  bool? collect;
  String? cid;
  String? cn;
  String? sourceId;

  // 内部打开试卷结果查看接口返回的，做题次数
  int? doingNumber;

  // 内部打开试卷结果查看接口返回的，错误次数
  int? errorNumber;

  // 试题排序，获取试题集合接口里面返回的
  int? sort;

  // 试题分数，获取试题集合接口里面返回的
  double? score;

  PracticeQuestionModel({
    this.id,
    this.firstType,
    this.type,
    this.difficulty,
    this.stem,
    this.quOption,
    this.answerDesc,
    this.children,
    this.record,
    this.rightAnswer,
    this.answerBase64,
    this.sign,
    this.collect,
    this.cid,
    this.cn,
    this.sourceId,
    this.doingNumber,
    this.errorNumber,
    this.sort,
    this.score,
  });

  PracticeQuestionModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    if (json['firstType'] != null) {
      firstType = FirstTypeEnum.getFirstTypeByCode(json['firstType']);
    }
    type = json['type'];
    difficulty = json['difficulty'];
    if (json['stem'] != null) {
      stem = <Stem>[];
      json['stem'].forEach((v) {
        stem!.add(Stem.fromJson(v));
      });
    }
    if (json['quOption'] != null) {
      quOption = json["quOption"];
    }
    if (json['answerDesc'] != null) {
      answerDesc = <Stem>[];
      json['answerDesc'].forEach((v) {
        answerDesc!.add(Stem.fromJson(v));
      });
    }
    children = json['children'];
    if (json["record"] != null) {
      record = RecordModel.fromJson(json['record']);
    }
    rightAnswer = json['rightAnswer'];
    answerBase64 = json['answerBase64'];
    sign = json['sign'];
    collect = json['collect'];
    cid = json['cid'];
    cn = json['cn'];
    sourceId = json['sourceId'];
    if (json["doingNumber"] != null) {
      doingNumber = json["doingNumber"];
    }
    if (json["errorNumber"] != null) {
      errorNumber = json["errorNumber"];
    }
    if (json["sort"] != null) {
      sort = json["sort"];
    }
    if (json["score"] != null) {
      score = double.parse(json["score"].toString());
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    if (firstType != null) {
      data['firstType'] = firstType!.name;
    }
    data['type'] = type;
    data['difficulty'] = difficulty;
    if (stem != null) {
      data['stem'] = stem!.map((v) => v.toJson()).toList();
    }
    if (quOption != null) {
      data['quOption'] = quOption;
    }
    if (answerDesc != null) {
      data['answerDesc'] = answerDesc!.map((v) => v.toJson()).toList();
    }
    data['children'] = children;
    if (record != null) {
      data['record'] = record!.toJson();
    }
    data['rightAnswer'] = rightAnswer;
    data['answerBase64'] = answerBase64;
    data['sign'] = sign;
    data['collect'] = collect;
    data['cid'] = cid;
    data['cn'] = cn;
    data['sourceId'] = sourceId;
    if (doingNumber != null) {
      data["doingNumber"] = doingNumber;
    }
    if (errorNumber != null) {
      data["errorNumber"] = errorNumber;
    }
    if (sort != null) {
      data["sort"] = sort;
    }
    if (score != null) {
      data["score"] = score;
    }
    return data;
  }
}

class Stem {
  String? vl;
  String? tp;

  Stem({this.vl, this.tp});

  Stem.fromJson(Map<String, dynamic> json) {
    vl = json['vl'];
    tp = json['tp'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['vl'] = vl;
    data['tp'] = tp;
    return data;
  }
}

class QuOption {
  List<Stem>? content;
  dynamic option;

  QuOption({
    this.content,
    this.option,
  });

  QuOption.fromJson(Map<String, dynamic> json) {
    if (json['content'] != null) {
      content = <Stem>[];
      json['content'].forEach((v) {
        content!.add(Stem.fromJson(v));
      });
    }
    option = json['option'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    if (content != null) {
      data['content'] = content!.map((v) => v.toJson()).toList();
    }
    data['option'] = option;
    return data;
  }
}

class RecordModel {
  /// 答案
  dynamic as;

  /// 是否正确
  bool? rt;

  /// 答题时间
  int? t;

  RecordModel({
    this.as,
    this.rt,
    this.t,
  });

  RecordModel.fromJson(Map<String, dynamic> json) {
    as = json["as"];
    rt = json["rt"];
    t = json["t"];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data["as"] = as;
    data["rt"] = rt;
    data["t"] = t;
    return data;
  }
}
